<template>
  <el-main class="app-list">
    <div class="apps-grid">
      <el-card
        v-for="item in myapps"
        :key="item.name"
        class="app-card"
        shadow="hover"
      >
        <div class="app-block">
          <img class="app-img" :src="item.url" alt="应用图片" />
          <div class="app-meta">
            <div class="app-name">{{ item.name }}</div>
            <div class="app-download">下载次数：{{ item.location }}</div>
          </div>
        </div>
        <el-button type="primary" :href="item.url" target="_blank">安装</el-button>
        </el-card>
    </div>

    <!-- 如果没有数据，显示提示 -->
<!--    <div v-if="apps.length == 0" style="text-align: center; padding: 50px; color: #999;">-->
<!--      <p>暂无应用数据</p>-->
<!--      <p>请检查后端服务是否正常运行</p>-->
<!--    </div>-->
  </el-main>
</template>

<script setup lang="ts">
const props = defineProps({
  myapps: {
    type: Array,
    required: true
  },
  currentCategory: {
    type: String,
    required: true
  }
});

console.log('AppList 接收到的 props:', props);
</script>

<style scoped>
.app-list {
  background-color: #f5f7fa;
  padding: 20px;
}

.apps-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
}

.app-card {
  width: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 10px;
}

.app-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.app-img {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 16px;
  margin-bottom: 10px;
  background: #f0f0f0;
}

.app-meta {
  text-align: center;
  margin-bottom: 10px;
}

.app-name {
  font-weight: bold;
  margin-bottom: 5px;
  font-size: 16px;
}

.app-download {
  color: #888;
  font-size: 13px;
}

.el-button {
  width: 80%;
  margin: 0 auto;
}
</style>
